//
//  BIZHomeLiveStreamingCell.m
//  biz
//
//  Created by 小龙 on 2017/3/16.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZHomeLiveStreamingCell.h"
#import "BIZLiveRoomDetailInfoModel.h"
#import "BIZCycleScrollViewImagesModel.h"

@interface BIZHomeLiveStreamingCell ()
@property (weak, nonatomic) IBOutlet UIImageView *firstImageView;
@property (weak, nonatomic) IBOutlet UIImageView *secondImageView;
@property (weak, nonatomic) IBOutlet UILabel *firstDesLabel;
@property (weak, nonatomic) IBOutlet UILabel *secondDesLabel;
@property (strong, nonatomic) IBOutlet UIButton *statusBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *statusBtnWidth;
@property (strong, nonatomic) IBOutlet UIView *questionBackGroudVIew;
@property (strong, nonatomic) IBOutlet UIButton *questionButton;
@property (strong, nonatomic) IBOutlet UIView *questionRedPoint;

@end

@implementation BIZHomeLiveStreamingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSecondImageView)];
    
    [self.secondImageView addGestureRecognizer: tap];
    _questionBackGroudVIew.backgroundColor = HEXCOLOR(0xf1f1f1);
    
    [_questionButton setImage:[UIImage imageNamed:@"home_arrow"] forState:UIControlStateNormal];
    [_questionButton setTitleColor:COLOR_NAVBAR_BLUE forState:UIControlStateNormal];
    _questionButton.titleLabel.font = CHINESE_SYSTEM(12);
    [_questionButton setButtonImageTitleStyle:ButtonImageTitleStyleRight padding:3];
    [_questionButton addTarget:self action:@selector(pushToQAList:) forControlEvents:UIControlEventTouchUpInside];

    _questionRedPoint.layer.cornerRadius = 4;
    _questionRedPoint.layer.masksToBounds = YES;
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setLiveRoomInfoDataM:(BIZLiveRoomDetailInfoDataModel *)liveRoomInfoDataM {
    _liveRoomInfoDataM = liveRoomInfoDataM;
    if (liveRoomInfoDataM == nil) {
        return;
    }
    [SDWebImageTool imageView:self.firstImageView
                    imageName:liveRoomInfoDataM.cover
                  placeHolder:@"图层6"
                 showProgress:YES];
    
    
    DeLog(@"%d",liveRoomInfoDataM.status);
    
    if (liveRoomInfoDataM.status) {
        self.statusBtnWidth.constant = 46;
         [_statusBtn setTitle:@"直播中" forState:UIControlStateNormal];
         [_statusBtn setImage:[UIImage imageNamed:@"椭圆9"] forState:UIControlStateNormal];
        
    } else {
        self.statusBtnWidth.constant = 60;
        [_statusBtn setTitle:@"直播未开始" forState:UIControlStateNormal];
        [_statusBtn setImage:[UIImage imageNamed:@"直播未开始"] forState:UIControlStateNormal];

    }
    
    [self.statusBtn setButtonImageTitleStyle:ButtonImageTitleStyleLeft padding:2];
    
//    [self.contentView.subviews enumerateObjectsUsingBlock:^(UIView *childView, NSUInteger idx, BOOL * _Nonnull stop) {
//        if ([childView isMemberOfClass:[LSPaoMaView class]]) {
//            [childView removeFromSuperview];
//            *stop = YES;
//            return;
//        }
//    }];
    
    if ([NSString widthForString:liveRoomInfoDataM.name fontSize:14 andHeight:17] > self.firstImageView.width) {
        
        self.firstDesLabel.hidden = YES;
        LSPaoMaView *view = [[LSPaoMaView alloc]initWithFrame:self.firstDesLabel.frame title:liveRoomInfoDataM.name];
        view.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:view];
        
    } else {
        self.firstDesLabel.hidden = NO;
        self.firstDesLabel.text = liveRoomInfoDataM.name;
    }
    
}


-(void)setLivePredictDataM:(BIZCycleScrollViewImagesDataModel *)livePredictDataM {
    _livePredictDataM = livePredictDataM;
    
    if (livePredictDataM.image == nil) {
        return;
    }
    
    [SDWebImageTool imageView:_secondImageView
                    imageName:livePredictDataM.image
                  placeHolder:@"图层6"
                 showProgress:YES];
    
//    [self.contentView.subviews enumerateObjectsUsingBlock:^(UIView *childView, NSUInteger idx, BOOL * _Nonnull stop) {
//        if ([childView isMemberOfClass:[LSPaoMaView class]]) {
//            [childView removeFromSuperview];
//            *stop = YES;
//            return;
//        }
//    }];
    
    if ([NSString widthForString:livePredictDataM.title fontSize:14 andHeight:17] > (self.secondImageView.width-71.5)) {
        self.secondDesLabel.hidden = YES;
        LSPaoMaView *view = [[LSPaoMaView alloc]initWithFrame:self.secondDesLabel.frame title:livePredictDataM.title];
        view.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:view];
        
    } else {
        self.secondDesLabel.hidden = NO;
        self.secondDesLabel.text = livePredictDataM.title;
    }
    
    _questionRedPoint.backgroundColor = _hasNew?HEXCOLOR(0xff0000):[UIColor clearColor];
}

- (void)tapSecondImageView {
    
    !self.clickSecondImgBlock ?:self.clickSecondImgBlock();
}

- (void)pushToQAList:(UIButton *)btn {
    !self.pushToQAListBlock ?:self.pushToQAListBlock();
}

@end
